package cruncher;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Random;

import utils.Logger;

public class FixingStrategy implements IFixingStrategy {

	Random rnd = new Random(System.currentTimeMillis());
	
	
	//TODO 
	//set priority [0,1] for every variable, sort them according to priority 
	/* (non-Javadoc)
	 * @see cruncher.IFixingStrategy#getFixedSet(cruncher.Solution)
	 */
	@Override
	public HashSet<Variable> getFixedSet(Solution sol, double fixedFraction) {
		Logger.INFO(String.format("Fixing %.2f %% variables", fixedFraction * 100));

		LinkedList<Variable> l = new LinkedList<Variable>();
		l.addAll(getVariableCandidates(sol));
		//make it random
		java.util.Collections.shuffle(l);

		int fixedSetSize = (int)(l.size() * fixedFraction);
		
		HashSet<Variable> fixed = new HashSet<Variable>();
		fixed.addAll(l.subList(0,fixedSetSize));
		
        return fixed;
	}

	protected HashSet<Variable> getVariableCandidates(Solution sol)
	{
		return sol.getDecisionVariables();
	}

}
